package com.atguigu.jinx.enums;

/**
 * @author steve
 * @date 2025/08/27 18:25
 */

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ProcessStatus {
    PENDING((byte)0, "待审核"),
    PROCESSING((byte)1, "处理中"),
    SUCCESS((byte)2, "成功"),
    FAILED((byte)3, "失败");

    private final byte code;
    private final String name;

    /**
     * 根据 code 获取枚举
     */
    public static ProcessStatus fromCode(byte code) {
        for (ProcessStatus status : ProcessStatus.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown code: " + code);
    }

    /**
     * 根据 code 获取 name
     */
    public static String getNameByCode(byte code) {
        for (ProcessStatus status : ProcessStatus.values()) {
            if (status.getCode() == code) {
                return status.getName();
            }
        }
        return null; // 或者抛异常，看你业务需要
    }

    public boolean isSuccess() {
        return this == SUCCESS;
    }

    public boolean isFailed() {
        return this == FAILED;
    }

    public boolean isProcessing() {
        return this == PROCESSING;
    }

    public boolean isPending() {
        return this == PENDING;
    }
}
